<?php
namespace app\tool;
use think\facade\Db;
/**
 *
 */
class File
{
    //查找所有文件夹内文件
    public static function findAllDir($filedir='',$level=1){
        if(!$filedir)  return '路径不正确！';
        static $result=[];
        $files = scandir($filedir);
        foreach ($files as $file) {
            if ($file != '.' && $file != '..') {
                if (is_dir($filedir . '/' . $file)) {
                    self::findAllDir($filedir . '/' . $file);
                } else {
                    $result[] =$filedir . '/' . $file;//basename($file);
                }
            }
        }
        return $result;
    }

    //复制文件夹
    public static function copyFolder($source='', $destination='') {
        if (!file_exists($destination)) {
            mkdir($destination, 0777, true);
        }
        $directory = opendir($source);
        while ($file = readdir($directory)) {
            if ($file != "." && $file != "..") {
                $source_file = $source . "/" . $file;
                $destination_file = $destination . "/" . $file;
                if (is_dir($source_file)) {
                    self::copyFolder($source_file, $destination_file);
                } else {
                    copy($source_file, $destination_file);
                }
            }
        }
        closedir($directory);
        return true;
    }



}